/*
 * Copyright (C) 2012 Rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import rpg.Maps.Map;
import rpg.entities.*;

/**
 * rothens.tumblr.com
 * @author Rothens
 */
public class EntityHandler {

	private List<Entity> active;

	public EntityHandler() {
		active = new ArrayList<Entity>();
	}

	public Entity getEntity(Character c, Map map, int loc) {
		switch (c) {
			case 'c':
				return new Chest(map, loc, 0);
			case 'g':
				return new Chest(map, loc, 1);
			case 'b':
				return new Chest(map, loc, 2);
			case 'r':
				return new Chest(map, loc, 3);
			case 'o':
				return new Rooster(map, new Location(loc, map));
			case 'h':
				return new Chick(map, new Location(loc, map));
			case 'z':
				return new Zombie1(map, new Location(loc, map));
		}
		return null;
	}
	
	public Entity spawnZombie(Map map, int loc, Player p){
		return new Zombie1(map, new Location(loc, map), p);
	}

	public void tick() {
		Iterator<Entity> it = active.iterator();
		while (it.hasNext()) {
			Entity e = it.next();
			if (e instanceof Player) {
				continue;
			}
			if (!e.tick()) {
				it.remove();
			}
		}
	}

	public void addToActive(Entity e) {
		active.add(e);
	}
}
